# Maintainer: David Runge <dvzrv@archlinux.org>
# Contributor: Ray Rashif <schiv@archlinux.org>
# Contributor: speps <speps at aur dot archlinux dot org>

pkgbase=sratom
pkgname=(sratom{,-docs})
pkgver=0.6.16
pkgrel=1
pkgdesc="An LV2 Atom RDF serialisation library"
arch=(loong64 x86_64)
url="https://drobilla.net/software/sratom.html"
license=(ISC)
makedepends=(
  doxygen
  lv2
  meson
  python-sphinx
  python-sphinx-lv2-theme
  python-sphinxygen
  serd
  sord
)
source=(https://download.drobilla.net/$pkgname-$pkgver.tar.xz{,.sig})
sha512sums=('8e01eec642bff63745e8d99a814780ff34e4b79cc99699a1bb7ddac60da8808231d3b4a615a1d87464cbcf4dc26b8ec39e71688a268d493df71dc75892bf6479'
            'SKIP')
b2sums=('e78bc572d990ce6914f3276d1b110cb3ba01213f5a084d8548009bf9226107c820f9f86f4cf22ae8076dd9d44bdb5e8b4bc623f67759150fb267b6ccf673a1f7'
        'SKIP')
validpgpkeys=('907D226E7E13FA337F014A083672782A9BF368F3') # David Robillard <d@drobilla.net>

_pick() {
  local p="$1" f d; shift
  for f; do
    d="$srcdir/$p/${f#$pkgdir/}"
    mkdir -p "$(dirname "$d")"
    mv "$f" "$d"
    rmdir -p --ignore-fail-on-non-empty "$(dirname "$f")"
  done
}

build() {
  arch-meson $pkgname-$pkgver build
  meson compile -C build
}

check() {
  meson test -C build
}

package_sratom() {
  depends=(
    glibc
    serd libserd-0.so
    sord libsord-0.so
    lv2
  )
  provides=(libsratom-0.so)
  optdepends=('sratom-docs: for developer documentation')

  meson install -C build --destdir "$pkgdir"
  (
    cd "$pkgdir"
    _pick $pkgname-docs usr/share/doc
  )
  install -vDm 644 $pkgname-$pkgver/COPYING -t "$pkgdir/usr/share/licenses/$pkgname/"
  install -vDm 644 $pkgname-$pkgver/{NEWS,README.md} -t "$pkgdir/usr/share/doc/$pkgname/"
}

package_sratom-docs() {
  pkgdesc+=" - documentation"

  mv -v $pkgname/* "$pkgdir"
  mv -v "$pkgdir/usr/share/doc/"sratom{-0,}
}
